<?php
	
class mehiron	
{	
	//public $mehironFieldNames = array("mehiron_number","product1","product2","product3","product4","product5","product6","product7","product8","product9","product10","product11","product12","product13","product14","product15","product16");						
	public function  viewMehironBasis()
	{
		#----- view and filter sql query generator  ------#
		$sql_query="SELECT * FROM mehiron WHERE mehiron_number = 1 ";
		#----- view and filter sql query generator  ------#
		
		#----- get data from DB ------#
		require("../includes/openConnection.php"); 
		$q = mysql_query($sql_query) or die(mysql_error());
		require("../includes/closeConnection.php");
		#----- get data from DB ------#
		
		#----- return json ------#
		$rows = array();
		while($r = mysql_fetch_assoc($q)) 
			{	
			//	$r['perosnid'] = $r['id'];
			//  unset($r['id']);
			$rows[] = $r;
			}
		print json_encode($rows);
		#----- return json ------#
		
	}
        
        
        public function  viewAgentMehiron()
	{
            
                 require("../includes/openConnection.php"); 
		$sql_query="SELECT mehiron_number FROM  agent WHERE person_number='{$_POST['agent_number']}' ";
                $q = mysql_query($sql_query) or die(mysql_error());
                $r = mysql_fetch_assoc($q);
                $mehiron_number=$r['mehiron_number'];
                
                
		$sql_query="SELECT * FROM mehiron WHERE mehiron_number = '{$mehiron_number}' ";
		$q1 = mysql_query($sql_query) or die(mysql_error());
		require("../includes/closeConnection.php");
		#----- get data from DB ------#
		
		#----- return json ------#
		$rows = array();
		while($r1 = mysql_fetch_assoc($q1)) 
			{	
			//	$r['perosnid'] = $r['id'];
			//  unset($r['id']);
			$rows[] = $r1;
			}
		print json_encode($rows);
		#----- return json ------#
		
	}
	
	public function  editMehiron()
	{
		
		#----- update sql query generator  ------#
		$sql_query="UPDATE mehiron SET  `product1` =  '{$_POST ['product1']}',`product2` =  '{$_POST ['product2']}',`product3` =  '{$_POST ['product3']}',`product4` =  '{$_POST ['product4']}',`product5` =  '{$_POST ['product5']}',`product6` =  '{$_POST ['product6']}',`product7` =  '{$_POST ['product7']}',`product8` =  '{$_POST ['product8']}',`product9` =  '{$_POST ['product9']}',`product10` =  '{$_POST ['product10']}',`product11` =  '{$_POST ['product11']}',`product12` =  '{$_POST ['product12']}',`product13` =  '{$_POST ['product13']}',`product14` =  '{$_POST ['product14']}',`product15` =  '{$_POST ['product15']}',`product16` =  '{$_POST ['product16']}' WHERE mehiron_number ='{$_POST ['mehiron_number']}';";
		#----- update sql query generator  ------#
		
		#----- update data in DB ------#
		require("../includes/openConnection.php");
		if(mysql_query($sql_query)) echo "ok";
		else echo mysql_error();
		require("../includes/closeConnection.php");
		#----- update data in DB ------#
		
	}
        
        public function  editAgentMeiron()
	{
            require("../includes/openConnection.php");
		if ($_POST ['mehiron_number']==1)
                {
                    $sql_query="INSERT INTO mehiron (`mehiron_number`, `product1`, `product2`, `product3`, `product4`, `product5`, `product6`, `product7`, `product8`, `product9`, `product10`, `product11`, `product12`, `product13`, `product14`, `product15`, `product16`) VALUES (NULL, '{$_POST ['product1']}', '{$_POST ['product2']}', '{$_POST ['product3']}', '{$_POST ['product4']}', '{$_POST ['product5']}', '{$_POST ['product6']}', '{$_POST ['product7']}', '{$_POST ['product8']}', '{$_POST ['product9']}', '{$_POST ['product10']}', '{$_POST ['product11']}', '{$_POST ['product12']}', '{$_POST ['product13']}', '{$_POST ['product14']}', '{$_POST ['product15']}', '{$_POST ['product16']}');";
                     mysql_query($sql_query);
                    $mehironNumber=mysql_insert_id();
                    $sql_query="UPDATE agent SET  `mehiron_number` =  '{$mehironNumber}' WHERE person_number ='{$_POST ['agent_number']}';";
                 if(mysql_query($sql_query)) echo "ok";
                }
                else {
		#----- update sql query generator  ------#
		$sql_query="UPDATE mehiron SET  `product1` =  '{$_POST ['product1']}',`product2` =  '{$_POST ['product2']}',`product3` =  '{$_POST ['product3']}',`product4` =  '{$_POST ['product4']}',`product5` =  '{$_POST ['product5']}',`product6` =  '{$_POST ['product6']}',`product7` =  '{$_POST ['product7']}',`product8` =  '{$_POST ['product8']}',`product9` =  '{$_POST ['product9']}',`product10` =  '{$_POST ['product10']}',`product11` =  '{$_POST ['product11']}',`product12` =  '{$_POST ['product12']}',`product13` =  '{$_POST ['product13']}',`product14` =  '{$_POST ['product14']}',`product15` =  '{$_POST ['product15']}',`product16` =  '{$_POST ['product16']}' WHERE mehiron_number ='{$_POST ['mehiron_number']}';";
		#----- update sql query generator  ------#
		
		#----- update data in DB ------#
		
		if(mysql_query($sql_query)) echo "ok";
		else echo mysql_error();
                }
		require("../includes/closeConnection.php");
		#----- update data in DB ------#
		
	}
	
	public function  addMehiron()
	{
		#----- insert data to DB ------#
		require("../includes/openConnection.php");  
			if(mysql_query("INSERT INTO mehiron (`mehiron_number`, `product1`, `product2`, `product3`, `product4`, `product5`, `product6`, `product7`, `product8`, `product9`, `product10`, `product11`, `product12`, `product13`, `product14`, `product15`, `product16`) VALUES (NULL, '{$_POST ['product1']}', '{$_POST ['product2']}', '{$_POST ['product3']}', '{$_POST ['product4']}', '{$_POST ['product5']}', '{$_POST ['product6']}', '{$_POST ['product7']}', '{$_POST ['product8']}', '{$_POST ['product9']}', '{$_POST ['product10']}', '{$_POST ['product11']}', '{$_POST ['product12']}', '{$_POST ['product13']}', '{$_POST ['product14']}', '{$_POST ['product15']}', '{$_POST ['product16']}');")) echo "ok";
			else echo mysql_error();
		require("../includes/closeConnection.php");
		#----- insert data to DB ------#	
	}
	
	public function  deleteMehiron()
	{
		#----- delete data to DB ------#
		require("../includes/openConnection.php");  
		if(mysql_query("DELETE FROM mehiron WHERE mehiron_number='{$_POST ['mehiron_number']}';")) echo "ok";
		require("../includes/closeConnection.php");
		#----- delete data to DB ------#	
			
	}

        
//         public function  get_Mehiron_Names_With_Prices()
//	{
//            
//                 require("../includes/openConnection.php"); 
//
//		$sql_query="SELECT * FROM mehiron WHERE mehiron_number = '{$_POST ['mehiron_number']}' ";
//		$q1 = mysql_query($sql_query) or die(mysql_error());
//		require("../includes/closeConnection.php");
//		#----- get data from DB ------#
//		
//		#----- return json ------#
//		$rows = array();
//                echo $sql_query;
//		while($r1 = mysql_fetch_assoc($q1)) 
//			{	
//			//	$r['perosnid'] = $r['id'];
//			//  unset($r['id']);
//			$rows[] = $r1;
//			}
//		print json_encode($rows);
//		#----- return json ------#
//		
//	}
	
}




?>